package com.zhb.zhbojbackenduserservice.controller.inner;

import com.zhb.zhbojbackendcommon.common.BaseResponse;
import com.zhb.zhbojbackendcommon.common.ErrorCode;
import com.zhb.zhbojbackendcommon.common.ResultUtils;
import com.zhb.zhbojbackendcommon.exception.BusinessException;
import com.zhb.zhbojbackendmodel.model.entity.User;
import com.zhb.zhbojbackendserviceclient.service.UserFeignClient;
import com.zhb.zhbojbackenduserservice.service.UserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.List;

import static com.zhb.zhbojbackendcommon.constant.UserConstant.USER_LOGIN_STATE;

/**
 * 该服务仅内部调用，不是给前端的
 */
@RestController
@RequestMapping("/inner")
public class UserInnerController implements UserFeignClient {

    @Resource
    private UserService userService;

    /**
     * 根据 id 获取用户
     * @param userId
     * @return
     */
    @Override
    @GetMapping("/get/id")
    public User getById(@RequestParam("userId") long userId) {
        return userService.getById(userId);
    }

    /**
     * 根据 id 获取用户列表
     * @param idList
     * @return
     */
    @Override
    @GetMapping("/get/ids")
    public List<User> listByIds(@RequestParam("idList") Collection<Long> idList) {
        return userService.listByIds(idList);
    }
    @Override
    @PostMapping("/update/id")
    public boolean updateById(@RequestBody User user){
        return userService.updateById(user);
    }

    @Override
    @RequestMapping("/logout")
    public boolean logout(@RequestParam("token") String token){
        return userService.userLogoutBytoken(token);
    }

}
